<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layuiAdmin 网站用户 iframe 框</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link id="layuicss-layer" rel="stylesheet"
          href="https://www.layui.com/admin/std/dist/layuiadmin/layui/css/modules/layer/default/layer.css?v=3.1.1"
          media="all">
</head>
<body layadmin-themealias="default">

<form class="layui-form">
    <div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin"
         style="padding: 20px 0 0 0;">
        <div class="layui-form-item">
            <label class="layui-form-label">商品名称:</label>
            <div class="layui-input-inline">
                <input type="text" name="productName" lay-verify="required" placeholder="请输入商品名称" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品价格:</label>
            <div class="layui-input-inline">
                <input type="text" name="productPrice" lay-verify="required|pass" placeholder="请输入商品价格"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品库存:</label>
            <div class="layui-input-inline">
                <input type="text" name="productStack" lay-verify="required|pass" placeholder="请输入商品库存"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">商品类型:</label>
                <div class="layui-input-inline">
                    <select name="productType">
                        <option value="0">请选择商品类型</option>
                        <option th:each="product : ${productTypeList}" th:value="${product.id}"
                                th:text="${product.typeName}"></option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">商家:</label>
                    <div class="layui-input-inline">
                        <select name="productShopId">
                            <option value="0">请选择商家</option>
                            <option th:each="shop : ${shopList}" th:value="${shop.id}"
                                    th:text="${shop.shopName}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <!--  <div class="layui-form-item">
                  <label class="layui-form-label">角色权限:</label>
                  <div class="layui-input-block" th:each="menu : ${menuList}">
                      <input type="checkbox" name="roles" th:title="${menu.menuName}" th:value="${menu.id}">
                  </div>
              </div>-->

            <!-- <div class="layui-form-item">
                 <label class="layui-form-label">开关-默认开</label>
                 <div class="layui-input-block">
                     <input type="checkbox" checked="" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">
                 </div>
             </div>-->
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>
    </div>
</form>
<script src="/layuiadmin/layui/layui.js"></script>
<script th:inline="none">
    //添加数据功能
    layui.use(['form', 'layer', 'jquery'], function () {
        var form = layui.form
            , layer = layui.layer
            , $ = layui.jquery,
            table = layui.table
        //监听提交
        form.on('submit(formDemo)', function (data) {

            //获取checkbox[name='like']的值
            /* var arr = new Array();
             $("input:checkbox[name='roles']:checked").each(function(i){
                 arr[i] = $(this).val();
             });
             data.field.like = arr.join(",");//将数组合并成字符串*/
            $.ajax({
                url: '/addProduct',
                type: 'POST',
                dataType: 'json',
                data: {
                    productName: data.field.productName,
                    productPrice: data.field.productPrice,
                    productStack: data.field.productStack,
                    productType: data.field.productType,
                    productShopId: data.field.productShopId
                },
                success: function (msg) {
                    var returnCode = msg.code;
                    if (returnCode === 200) {
                        layer.closeAll('loading');
                        layer.load(2);
                        layer.msg("添加成功", {icon: 6});
                        setTimeout(function () {
                            window.parent.location.reload();//修改成功后刷新父界面
                        }, 1000);
                        //加载层-风格

                    } else {
                        layer.msg("已经存在该设备,不支持重复添加", {icon: 5});
                    }
                }
            })
            return false;
        });
    });
</script>
<style id="LAY_layadmin_theme">.layui-side-menu, .layadmin-pagetabs .layui-tab-title li:after, .layadmin-pagetabs .layui-tab-title li.layui-this:after, .layui-layer-admin .layui-layer-title, .layadmin-side-shrink .layui-side-menu .layui-nav > .layui-nav-item > .layui-nav-child {
    background-color: #20222A !important;
}

.layui-nav-tree .layui-this, .layui-nav-tree .layui-this > a, .layui-nav-tree .layui-nav-child dd.layui-this, .layui-nav-tree .layui-nav-child dd.layui-this a {
    background-color: #009688 !important;
}

.layui-layout-admin .layui-logo {
    background-color: #20222A !important;
}</style>
</body>
</html>